import { UserProfilesAPI } from '@/requset/api'
export default {
    namespaced: true,
    state: {
        userInfo: {
            // 昵称
            nickName: '',
            // 积分
            coin: 0,
            // 头像
            headImg: require('../../assets/img/userImg.f8bbec5e.png')
        },
        cartTotal: 0
    },
    mutations: {
        changeIsUserInfo(state, payload) {
            console.log("修改vuex中用户信息", payload);
            state.userInfo = payload.userInfo
            state.cartTotal = payload.cartTotal
        },
        // 初始化
        initUserInfo(state) {
            state.userInfo = {
                // 昵称
                nickName: '',
                // 积分
                coin: 0,
                // 头像
                headImg: require('../../assets/img/userImg.f8bbec5e.png')
            }
            state.cartTotal = 0;
        }
    },
    actions: {
        async asyncChangeIsUserInfo(context, payload) {
            let user = await UserProfilesAPI();
            context.commit("changeIsUserInfo", user.data)
        }
    }
}